from math import sqrt

def d(n):
	sum = 1
	for i in range(2,int(sqrt(n))):
		if ((n/i) == n//i):
			sum += i + n//i
	if (sqrt(n) == int(sqrt(n))):
		sum += int(sqrt(n))
	return sum

sum = 0
for a in range (2, 10000):
	b = d(a)
	if (b > a and b < 10000 and d(b) == a):
		sum += a + b

print(sum)